package com.ruoyi.cost.service.impl;

import com.ruoyi.cost.domain.FundCostT;
import com.ruoyi.cost.mapper.HouseCostTMapper;
import com.ruoyi.cost.service.IHouseCostTService;
import com.ruoyi.costQuery.domain.HouseCostT;
import com.ruoyi.data.DataUtils;
import com.ruoyi.door.domain.HouseDoorT;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 户管理Service业务层处理
 * 
 * @author lijie
 * @date 2023-04-20
 */
@Service
public class HouseCostTServiceImpl implements IHouseCostTService
{
    @Autowired
    private HouseCostTMapper houseCostTMapper;

    /**
     * 查询户管理
     * 
     * @param doorId 户管理主键
     * @return 户管理
     */
    @Override
    public FundCostT selectFundCostTByDoorId(Long doorId)
    {
        return houseCostTMapper.selectFundCostTByDoorId(doorId);
    }

    /**
     * 查询户管理列表
     * 
     * @param fundCostT 户管理
     * @return 户管理
     */
    @Override
    public List<FundCostT> selectFundCostTList(FundCostT fundCostT)
    {
        return houseCostTMapper.selectFundCostTList(fundCostT);
    }

    @Override
    public FundCostT selectFundCostTSum(FundCostT fundCostT)
    {
        return houseCostTMapper.selectFundCostTSum(fundCostT);
    }
    @Transactional
    @Override
    public int updateFundCostT(FundCostT fundCostT)
    {

        FundCostT doorTempVO = new FundCostT();
        HouseCostT houseCostT = new HouseCostT();
        doorTempVO = houseCostTMapper.selectFundCostTByDoorId(fundCostT.getDoorId());
        doorTempVO.setCreateDate(fundCostT.getCostDate());
        doorTempVO.setUserName(fundCostT.getUserName());
        doorTempVO.setTel(fundCostT.getTel());
        doorTempVO.setPapersCode(fundCostT.getPapersCode());
        doorTempVO.setCostDate(fundCostT.getCostDate());
        doorTempVO.setBalance(DataUtils.sumMoney(doorTempVO.getBalance(), doorTempVO.getCostMoney()));
        doorTempVO.setBalanceSum(DataUtils.sumMoney(doorTempVO.getBalanceSum(), doorTempVO.getCostMoney()));
        int costId = houseCostTMapper.getCostId();
        houseCostT.setSerial(String.valueOf(costId+1));
        houseCostT.setCostDate(fundCostT.getCostDate());
        houseCostT.setCreater(fundCostT.getCreater());
        houseCostT.setRemark(fundCostT.getRemark());
        houseCostT.setHouseId(fundCostT.getHouseId());
        houseCostT.setCostBillType(fundCostT.getCostBillType());
        houseCostT.setCostBillWay(fundCostT.getCostBillWay());
        houseCostT.setCostMoney(doorTempVO.getCostMoney());
        houseCostTMapper.insertHouseCostT(houseCostT);
        houseCostTMapper.updateHouseDoorT(doorTempVO);
        return costId;
    }



}
